package com.lantu.wisdom.controller;


import com.lantu.framework.common.utils.ResponseWrapper;
import com.lantu.wisdom.dto.AddQuestionDTO;
import com.lantu.wisdom.model.WAnswer;
import com.lantu.wisdom.model.WQuestion;
import com.lantu.wisdom.service.WAnswerApi;
import com.lantu.wisdom.service.WQuestionApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zch
 * @since 2021-06-15
 */
@RestController
@RequestMapping("/wAnswer")
@Api(tags = "回复相关")
public class WAnswerController {

    @Autowired
    private WAnswerApi wAnswerApi;

    @Autowired
    private WQuestionApi wQuestionApi;

    @ApiOperation(value = "问题回复")
    @RequestMapping(value = "/reversion", method = RequestMethod.POST)
    public ResponseWrapper reversion(@RequestParam String answer,@RequestParam Integer questionId) {
        WAnswer answer1 = new WAnswer();
        answer1.setAnswer(answer);
        answer1.setQuestionId(questionId);
        answer1.setCreateTime(System.currentTimeMillis());
        boolean save = wAnswerApi.save(answer1);
        if(save){
            WQuestion question = new WQuestion();
            question.setId(questionId);
            question.setReply(2);
            question.setState(2);
            question.setUpdateTime(System.currentTimeMillis());
            wQuestionApi.updateById(question);
        }
        return ResponseWrapper.success(save);
    }

}

